<template>
	<view>
		<FullscreenLoading :loading="loading" :config="config"></FullscreenLoading>
		<view class="muu-classroom" :class="[config.style]">
			<view class="main-section tabbar-bottom" >
				<view class="item" v-for="(item,index) in pageData.data" :key="index">
					<view v-if="item.type==='announce'">
						<Announce title="公告组件" type="announce" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='article_list'">
						<ArticleList title="文章列表组件" type="article_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='category'">
						<Category title="分类组件" type="category" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='column_list'">
						<ColumnList title="专栏列表组件" type="column_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='category_nav'">
						<CategoryNav title="图文导航组件" type="category_nav" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='custom_form'">
						<CustomForm title="自定义表单组件" type="custom_form" :params="item" :config="config" />
					</view>
					<view v-if="item.type==='custom_text'">
						<CustomText title="自定义文本组件" type="custom_text" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='exam_paper_list'">
						<ExamPaperList title="题库试卷组件" type="exam_paper_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='knowledge_list'">
						<KnowledgeList title="课程列表组件" type="knowledge_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='live_list'">
						<LiveList title="直播课堂列表组件" type="live_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='miniprogram_live_list'">
						<MiniprogramLiveList title="小直播列表组件" type="miniprogram_live_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='material_list'">
						<MaterialList title="资料下载列表组件" type="material_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='member'">
						<Member title="会员服务组件" type="member" :config="config" />
					</view>
					<view v-if="item.type==='offline_list'">
						<OfflineList title="线下课列表组件" type="offline_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='search'">
						<Search title="搜索组件" type="search" :config="config" />
					</view>
					<view v-if="item.type==='slideshow'">
						<SlideShow title="轮播组件" type="slideshow" :slideshowStyle="Number(item.style)" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='single_img'">
						<SingleImg title="单图广告组件" type="single_img" :singleImgStyle="Number(item.style)" :params="item.data" :config="config"/>
					</view>
					<view v-if="item.type==='teacher_list'">
						<TeacherList title="教师列表组件" type="teacher_list" :singleImgStyle="Number(item.style)" :params="item.data":config="config" />
					</view>
					<view v-if="item.type==='weixin'">
						<Weixin title="关注公众号组件" type="weixin" :thisStyle="Number(item.style)" :config="config" />
					</view>
					<view v-if="item.type==='minishop_goods_list'">
						<MinishopGoodsList title="云小店商品列表组件" type="minishop_goods_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='activity_list'">
						<ActivityList title="线下活动列表组件" type="activity_list" :params="item.data" :config="config" />
					</view>
					<view v-if="item.type==='scoreshop_goods_list'">
						<ScoreshopGoodsList title="积分商城商品列表组件" type="scoreshop_goods_list" :params="item.data" :config="config" />
					</view>
					<!-- #ifdef H5 -->
					<view v-if="item.type==='forum_list'">
						<ForumList title="社群列表组件" type="forum_list" :params="item.data" :config="config" />
					</view>
					<!-- #endif -->
				</view>
				<template v-if="pageData">
					<CopyRight :data="config.copyright" />
				</template>
			</view>
			<tabBar />
		</view>
	</view>
	
</template>

<script>
	import { mapState,mapMutations,mapActions } from 'vuex'
	//DIY组件 按首字母顺序排列
	import ActivityList from '@/common/diys/ActivityList/ActivityList.vue' //线下活动组件
	import Announce from '@/common/diys/Announce/Announce.vue' //公告组件
	import ArticleList from '@/common/diys/ArticleList/ArticleList.vue' //文章列表组件
	import Category from '@/common/diys/Category/Category.vue' //分类组件
	import CategoryNav from '@/common/diys/CategoryNav/CategoryNav.vue' //图文导航组件
	import ColumnList from '@/common/diys/ColumnList/ColumnList.vue' //专栏列表组件
	import CustomForm from '@/common/diys/CustomForm/CustomForm.vue' //自定义表单组件
	import CustomText from '@/common/diys/CustomText/CustomText.vue' //自定义文本组件
	import ExamPaperList from '@/common/diys/ExamPaperList/ExamPaperList.vue' //题库试卷组件
	import KnowledgeList from '@/common/diys/KnowledgeList/KnowledgeList.vue' //课程列表组件
	import LiveList from '@/common/diys/LiveList/LiveList.vue' //直播课堂列表组件
	import MiniprogramLiveList from '@/common/diys/MiniprogramLiveList/MiniprogramLiveList.vue' //小直播列表组件
	import MaterialList from '@/common/diys/MaterialList/MaterialList.vue' //资料下载列表组件
	import Member from '@/common/diys/Member/Member.vue' //会员服务组件
	import MinishopGoodsList from '@/common/diys/MinishopGoodsList/MinishopGoodsList.vue' //云小店商品列表组件
	import OfflineList from '@/common/diys/OfflineList/OfflineList.vue' //线下课列表组件
	import ScoreshopGoodsList from '@/common/diys/ScoreshopGoodsList/ScoreshopGoodsList.vue' //积分商城商品列表组件
	import ForumList from '@/common/diys/ForumList/ForumList.vue' //社群列表组件
	import Search from '@/common/diys/Search/Search.vue' //搜索组件
	import SlideShow from '@/common/diys/SlideShow/SlideShow.vue' //轮播组件
	import SingleImg from '@/common/diys/SingleImg/SingleImg.vue' //单图广告组件
	import TeacherList from '@/common/diys/TeacherList/TeacherList.vue' //教师列表组件
	import Weixin from '@/common/diys/Weixin/Weixin.vue' //关注公众号组件
	
	import CopyRight from '@/common/components/copyright.vue' //自定义版权
	import TabBar from "../common/tabBar.vue" //底部导航

	export default {
		name: 'index',
		components: {
			ActivityList,
			Announce,
			ArticleList,
			Category,
			CategoryNav,
			ColumnList,
			CustomForm,
			CustomText,
			ExamPaperList,
			ForumList,
			KnowledgeList,
			LiveList,
			MiniprogramLiveList,
			MaterialList,
			Member,
			MinishopGoodsList,
			OfflineList,
			ScoreshopGoodsList,
			ForumList,
			Search,
			SlideShow,
			SingleImg,
			TeacherList,
			Weixin,
			CopyRight,
			TabBar,
		},
		data() {
			return {
				loading: true,
				urlParams: {}, //url传递过来的参数
				pageData : {}, //页面数据
			}
		},
		
		onReady() {
			//console.log('onReady')
			//this.loading = false;
		},
		onPageScroll(e) {
			
		},
		async onLoad(option) {
			await this.$onLaunched;
			//获取url参数
			this.urlParams = option
			await this.setConfigAsync()
			await this.getPageData()
			await this.initPage(this.config)
			await this.$nextTick(() => {
				this.loading = false
			})
		},
		created() {
			
		},
		mounted() {
			
		},
		
		computed: {
			...mapState(['config'])
		},
		methods: {
			...mapActions([
				'setConfigAsync'
			]),
			
			/**
			 * 初始化页面
			 */
			initPage(config) {
				console.log(config)
				//设置原生导航栏标题
				uni.setNavigationBarTitle({
				　　title:this.pageData.title
				})
				// H5端执行
				//#ifdef H5
				let url = window.location.href
				let shareData = {
					title : this.pageData.title,
					desc : this.pageData.description,
					img: config.share.icon
				}
				this.wechat.share(shareData,url);
				//#endif
			},

			/**
			 * 获取页面数据
			 */
			getPageData (){
				let that = this
				return new Promise((resolve, reject) => {
					let params = this.urlParams
					let data = {}
						data.id = this.urlParams.id,
						data.m = 'muu_classroom'
						if(params.hasOwnProperty("promoter_uid") && params.promoter_uid !== undefined){
							data.promoter_uid = params.promoter_uid
						}
					//获取自定义页面数据
					let url = '';
						//#ifdef MP-WEIXIN
						url = 'entry/wxapp/page'
						//#endif
						//#ifdef H5
						url = 'entry/site/page'
						//#endif
					this.util.request({
						url : url,
						data : data,
						success: function (res) {
							//console.log(res.data.code);
							if (res.data.code == 200) {
								that.pageData = res.data.data
								//设置原生导航栏
								that.setNavigation(res.data.data);
							}
							resolve(res)
						}
					})
				})
				
			},
			
			setNavigation: function(data) {
				let that = this
				//更改小程序原生导航栏
				uni.setNavigationBarTitle({
					title: data.title
				})
			}
		},
		
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage() {
			// 分享(分销)用户ID
			let promoterUid = this.userInfo.memberInfo.uid || 0
			let share = {
				title : this.pageData.title,
				path : '@/muu_classroom/pages/index/custom?' + 'id=' + this.pageData.id + '&promoter_uid=' + promoterUid,
				desc : this.pageData.description,
				success : function(){
					
				},
			}
			
			return share
		},
		/**
		 * 监听用户点击右上角转发到朋友圈
		 */
		onShareTimeline() {
			
		},
	}
</script>

<style lang="scss">

</style>
